import store from '@/store'

export function checkAuth() {
  const publicPages = ['/pages/login/index', '/pages/login/register']
  const currentPage = getCurrentPages().pop()?.route || ''
  const isPublicPage = publicPages.some(path => currentPage.includes(path))
  
  if (!store.state.token && !isPublicPage) {
    uni.redirectTo({
      url: '/pages/login/index',
      success: () => {
        uni.showToast({
          title: '请先登录',
          icon: 'none'
        })
      }
    })
    return false
  }
  return true
}